package weekMatch.one_102;

import java.util.*;

public class LeeCode_02 {
    public static void main(String[] args) {
        System.out.println(findMatrix(new int[]{1, 3, 4, 1, 2, 3, 1}));
        System.out.println(findMatrix(new int[]{1,2,3,4}));
    }
    private static List<List<Integer>> findMatrix(int[] nums) {
        Map<Integer, Integer> map = new HashMap();
        for (int num : nums) {
            map.put(num, map.containsKey(num) ? map.get(num) + 1 : 1);
        }
        Set<Integer> keys = map.keySet();
        int max = 0;
        for (Integer key : keys) {
            max = Math.max(max, map.get(key));
        }
        List<List<Integer>> ans = new ArrayList<>(max);
        for (int i = 0; i < max; i++) {
            ans.add(new ArrayList<>());
        }
        for (Integer key : keys) {
            int count = map.get(key);
            for (int i = 0; i < count; i++) {
                ans.get(i).add(key);
            }
        }
        return ans;
    }
}
